/*
 * @Author: liuhandong 
 * @Date: 2024-05-11 10:20:45 
 */
import * as cc from 'cc';

const {ccclass, menu, property} = cc._decorator;


@ccclass("CMain")
@menu("Game/CMain")
export class CMain extends cc.Component {
    @property(cc.JsonAsset)
    private appSettings: cc.JsonAsset = null;

    @property({type:cc.Camera})
    uiCamera: cc.Camera = null;

    @property({type:cc.Camera})
    gameCamera: cc.Camera = null;

    private _syncOrtho = false;

    onLoad() {
        // optimizeLabel();
        // ASYNCQUEUE.init();
        // ASYNCQUEUE.addGroup(AsyncQueueType.UpdateRichText, 0.03);
        let replaceLh = cc.sys.localStorage.getItem("___lh__vms__");
        if(replaceLh) {
        }
        // 初始化适配
        this._onWindowResize();
    }

    update(dt: number): void {
        if(this.gameCamera.orthoHeight != this.uiCamera.orthoHeight && this._syncOrtho == false){
            this._syncOrtho = true;
            this.gameCamera.orthoHeight = this.uiCamera.orthoHeight;
        }
    }

    /**
     * 窗口变化
     */
    private _onWindowResize(){
        // 获取屏幕宽高
        let screenSize = cc.view.getVisibleSize();
        let screenWidth = screenSize.width;
        let screenHeight = screenSize.height;
        //设计分辨率
        let designWidth = 640;
        let designHeight = 1136;
        this._syncOrtho = false;
        // 计算屏幕宽高比和设计分辨率的宽高比
        let screenRatio = screenWidth / screenHeight;
        let designRatio = designWidth / designHeight;
        if (screenRatio <= designRatio) {
            cc.view.setResolutionPolicy(cc.ResolutionPolicy.FIXED_WIDTH);
        } else {
            cc.view.setResolutionPolicy(cc.ResolutionPolicy.FIXED_HEIGHT);
        }
    }
}